package com.example.travelservlet.plan.repository;

import com.example.travelservlet.entity.Plan;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;

/**
 * @author 30697
 */
public interface PlanRepository extends JpaRepository<Plan,String>, JpaSpecificationExecutor {
    List<Plan> findPlanByBeginTimeAndTotalPlanId(String beginTime,String totalPlanId);
//    List<Plan> findPlansBySequence(Integer sequence, Sort sort);
    void deleteByPlanId(String planId);

    List<Plan> findPlansByTotalPlanId(String totalPlanId);

    Plan findPlanByPlanId(String planId);

    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(value = "update plan set use_index=?2 where plan_id=?1", nativeQuery = true)
    void updateUseIndexByPlanId(String planId, int i);

    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(value = "update plan set use_index=0 where total_plan_id=?1", nativeQuery = true)
    void setUseIndexByPlanId(String totalPlanId);
}
